package com.webchat.act.repository.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import lombok.Data;

import java.util.Date;


@Data
@Entity
@Table(name = "web_chat_resource_behavior")
public class ResourceBehaviorEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Long id;

    @Column(name = "USER_ID")
    private String userId;

    @Column(name = "RESOURCE_INDEX")
    private Long resourceIndex;

    @Column(name = "RESOURCE_TYPE")
    private String resourceType;

    @Column(name = "BEHAVIOR_TYPE")
    private String behaviorType;

    @Column(name = "status")
    private Boolean status;

    @Column(name = "update_date")
    private Date updateDate;

    @Column(name = "create_date")
    private Date createDate;

    @Version
    @Column(name = "version")
    private Integer version;

    @PrePersist
    public void prePersist() {
        Date now = new Date();
        if (this.createDate == null) {
            this.createDate = now;
        }
    }

    @PreUpdate
    public void preUpdate() {
        this.updateDate = new Date();
    }
}
